/**
 * @addtogroup srt_storage_eeprom_comp
 * srt_storage_eeprom_comp
 * @{
 */
/**
 * @file         srt_storage_eeprom_comp.h
 * @brief        
 * @note    
 * @author       Akee(shengkun.you@hopechart.com,尤胜坤)
 *
 * @par          修改日志
 * <table>
 * <tr><th>Date        <th>Version               <th>Author                                    <th>Description
 * <tr><td>2022-12-07  <td>1.0                   <td>Akee(shengkun.you@hopechart.com,尤胜坤)   <td>创建初始版本
 * @copyright    杭州鸿泉物联网技术股份有限公司
 */
#ifndef _SRT_STORAGE_EEPROM_COMP_H_
#define _SRT_STORAGE_EEPROM_COMP_H_
#include "ofc/ofc_types.h"
#include "srt_storage_interface.h"
#include "srt_storage_nvm_interface.h"
#include "ofc/ofc_list.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct TSrtStorageEepromCompTag TSrtStorageEepromComp;
typedef struct TSrtStorageEepromCompEraseMsgTag TSrtStorageEepromCompEraseMsg;
struct TSrtStorageEepromCompEraseMsgTag
{
    UInt32 offset;  ///< 擦除偏移位置
    UInt32 size;    ///< 擦除大小
    Int32 result;   ///< 擦除结果, >=0,表示成功; <0，底层错误码
};

typedef void (*TSrtStorageEepromCompDoEraseCallback)(TSrtStorageEepromComp *self, TSrtStorageEepromCompEraseMsg *msg);


/**
 * 
 */

struct TSrtStorageEepromCompTag
{
    ISrtStorage srt_storage_;
    ISrtStorageNvm *storage_nvm_;
    UInt32 nvm_max_size_;
    TOfList cache_list_;
    UInt32 last_offset_;
    Bool is_delete_;
    Bool is_auto_format_;
    Bool is_init_;
    Bool is_delete_action_;
    TSrtStorageEepromCompDoEraseCallback DoErase_;
};

typedef struct TSrtStorageEepromCompParamTag TSrtStorageEepromCompParam;
struct TSrtStorageEepromCompParamTag
{
    ISrtStorageNvm *storage_nvm;
    UInt32 nvm_max_size;
    Bool is_auto_format; ///< 当发生错误时，是否允许自动格式化
};

/**
 * 构造函数
 * @param self: 对象指针
 * @return 
 */
void TSrtStorageEepromCompCreate(TSrtStorageEepromComp *self, TSrtStorageEepromCompParam *param);

/**
 * 析构函数
 * @param self: 对象指针
 * @return 
 */
void TSrtStorageEepromCompDestroy(TSrtStorageEepromComp *self);

/**
 * 析构函数
 * @param self: 对象指针
 * @return >=0: 存储的属性个数, <0: 参考 @ref THccMidSrtStorageErrorCodeEnum
 */
Int32 TSrtStorageEepromCompInit(TSrtStorageEepromComp *self);
void TSrtStorageEepromCompDone(TSrtStorageEepromComp *self);
ISrtStorage *TSrtStorageEepromCompInterface(TSrtStorageEepromComp *self);

void TSrtStorageEepromCompSetEraseEvent(TSrtStorageEepromComp *self, TSrtStorageEepromCompDoEraseCallback callback);

#ifdef __cplusplus
} // extern "C" {
#endif

#endif

/**
 * @} 
 */


